package com.ymatou.iapi.sellerquery.service;

import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.trading.api.parameter.GetLatestPaidOrdersResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 获取最近支付成功的订单信息接口Call FreeMaker Template自动生成代码
 */
public class GetLastestPaidOrdersCall extends YmatouBaseCall {
	private static String opurl = "api/App/GetLatestPaidOrders";

	public GetLastestPaidOrdersCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	public JSONObject getData() {
		JSONObject data = null;
		try {
			data = new JSONObject(getReturnData()).getJSONObject("data");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data;
	}

	public GetLatestPaidOrdersResponse getLatestPaidOrdersResponse() {
		return (GetLatestPaidOrdersResponse) FormatUtil.GSONToObject(
				DataUtil.Json.parseJsonObj(getData().toString()).toString(),
				GetLatestPaidOrdersResponse.class);
	}


	public class JsonOrderBean {
		int OrderId;
		int BuyerId;
		int SellerId;
		String ProductName;
		String ProductId;
		String ProductPicUrl;

		public int getOrderId() {
			return OrderId;
		}

		public void setOrderId(int orderId) {
			OrderId = orderId;
		}

		public int getBuyerId() {
			return BuyerId;
		}

		public void setBuyerId(int buyerId) {
			BuyerId = buyerId;
		}

		public int getSellerId() {
			return SellerId;
		}

		public void setSellerId(int sellerId) {
			SellerId = sellerId;
		}

		public String getProductName() {
			return ProductName;
		}

		public void setProductName(String productName) {
			ProductName = productName;
		}

		public String getProductId() {
			return ProductId;
		}

		public void setProductId(String productId) {
			ProductId = productId;
		}

		public String getProductPicUrl() {
			return ProductPicUrl;
		}

		public void setProductPicUrl(String productPicUrl) {
			ProductPicUrl = productPicUrl;
		}

	}
}
